package main;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileNameExtensionFilter;

class fileOpen {
    fileOpen() {
        super();
    }

    /**
     * @param parent = parent frame
     * @return file name of null
     */
    public File askFile(JFrame parent, String action, File defaultDir) {
        int ret = 0;
        
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Comma separated values","csv");
        JFileChooser fc = new JFileChooser();
        fc.addChoosableFileFilter(filter);
        
        fc.setCurrentDirectory(defaultDir);
        ret = fc.showDialog(parent, action);
        if (ret == JFileChooser.APPROVE_OPTION) {
            return fc.getSelectedFile();
        }
    return null;            
    }
}
